
cc.Class({
    extends: cc.Component,

    properties: {
        ProgressBar: {
            default: null,
            type: cc.ProgressBar
        },
    },

    onLoad () {
        this.loadGlobalRes(this, this.loadResult); 
        cc.loader.loadRes('config/wuxingConfig', (v1, v2) => {
            G_wuxingfenghuolu.configJson = v2.json.config
        })

        G_wuxingfenghuolu.userInfo = {
            gk:1,
            zuanshi:10000000
        }
    },
    
    loadGlobalRes(target, func) {
        this.target = target;
        this.func = func;
        //加载预制体资源
        var loadResName = {
            'prefabs/common/reduceBlood': 'prefab_reduceBlood',//飘血
            //所有敌人
            'prefabs/enemys/enemy1': 'prefab_enemy1',
            'prefabs/enemys/enemy2': 'prefab_enemy2',
            'prefabs/enemys/enemy3': 'prefab_enemy3',
            'prefabs/enemys/enemy4': 'prefab_enemy4',
            'prefabs/enemys/enemy5': 'prefab_enemy5',
            'prefabs/enemys/enemy6': 'prefab_enemy6',
            'prefabs/enemys/enemy7': 'prefab_enemy7',
            'prefabs/enemys/enemy8': 'prefab_enemy8',
            'prefabs/enemys/enemy9': 'prefab_enemy9',
            'prefabs/enemys/enemy10': 'prefab_enemy10',
            'prefabs/enemys/enemy11': 'prefab_enemy11',
            'prefabs/enemys/enemy12': 'prefab_enemy12',
            'prefabs/enemys/enemy13': 'prefab_enemy13',


            'prefabs/game/createPanel': 'prefab_createPanel',
            'prefabs/game/fangyuta': 'prefab_fangyuta',


            'prefabs/bullets/bullet_jin1': 'prefab_bullet_jin1',
            'prefabs/bullets/bullet_jin2': 'prefab_bullet_jin2',
            'prefabs/bullets/bullet_mu2': 'prefab_bullet_mu2',
            'prefabs/bullets/bullet_shui1': 'prefab_bullet_shui1',
            'prefabs/bullets/bullet_shui1_xiaoguo': 'prefab_bullet_shui1_xiaoguo',
            
          
        }
        cc.globalRes = {};
        this.loadResCount = 0
        var arr = Object.keys(loadResName);
        this.ResCount = arr.length;
        var that = this;
        Object.keys(loadResName).forEach(function (key) {
            cc.loader.loadRes(key, function (err, prefab) {
                if (err) {
                    cc.error(err.message || err);
                }else{
                    that.loadResCount++;
                    if (that.target != undefined && that.func != undefined) {
                        that.func(target, that.loadResCount, that.ResCount);
                    }
                    cc.globalRes[loadResName[key]] = prefab;
                    that.ProgressBar.progress = that.loadResCount/that.ResCount;
                }
            });
        })
    },
    //预加载资源结果
    loadResult(target, loadResCount, ResCount) {
        //资源加载成功，跳转到登录界面
        if (loadResCount == ResCount) {
            cc.director.loadScene("home",function(){
               
            })
        }
    },
});
